import {Api} from '@/api/type'
import ApiCommon from '@/api/common'
import {LoginInfo} from '@/type/user'

type R<T> = Api.Common.R<T>;

/**
 * 验证码
 */
export async function captcha(): Promise<R<{key: string; img: string}>> {
    return await ApiCommon.request.get<R<{key: string; img: string}>>('system/authorize/captcha')
}

/**
 * 登录
 * @param data 登录信息
 */
export async function login(data: {
    key: string;
    captcha: string;
    username: string;
    password: string;
}): Promise<R<string>> {
    return await ApiCommon.request.post<R<string>>('system/authorize/login', data)
}

/**
 * 退出
 */
export async function logout(): Promise<R<string>> {
    return await ApiCommon.request.post<R<string>>('system/authorize/logout')
}

/**
 * 获取登录信息
 */
export async function authorize(): Promise<R<LoginInfo>> {
    return await ApiCommon.request.get<R<LoginInfo>>('system/authorize/info')
}

export default {
    captcha,
    login,
    logout,
    authorize
}
